import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
import Login from "../views/Login";
import '../assets/css/globel.css'
import home from "../components/home";
import Welcome from "../views/Welcome";
import users from "../components/user/users";
import "../assets/css/globel.css"
import rights from "../components/power/rights";
import roles from "../components/power/roles";
import cate from "../components/goods/cate";
import params from "../components/goods/params";
import listshop from "../components/goods/listshop";
import add from "../components/goods/add";
import orders from "../components/classify/orders";
import report from "../components/report/report";

Vue.use(VueRouter);

  const routes = [
  {
    path: '/',
    redirect:'/login'
  },
    {
      path: '/login',
      component: Login
    },
    {
      path:'/home',
      component:home,
      redirect:"/welcome",
      children:[
        {path:'/welcome',component: Welcome},
        {path: '/users',component: users},
        {path:'/rights',component:rights},
        {path:'/roles',component:roles},
        {path:'/categories',component:cate},
        {path:'/params',component:params},
        {path:'/goods',component:listshop},
        {path:'/goods/add',component:add},
        {path:'/orders',component:orders},
        {path:'/reports',component:report}
      ]
    }

];

const router = new VueRouter({
  routes
});
router.beforeEach((to,from,next)=>{
  if(to.path==='/login')
    return next();
  const tokenStr=window.sessionStorage.getItem('token');
  if(!tokenStr)
    return next('/login');
  next();
});

export default router
